package refactortips.editors.codeSmells;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;

import refactortips.editors.AbstractRefactorTipsEditor;

public class RefusedBequestEditor extends AbstractRefactorTipsEditor {

	protected final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	
	public RefusedBequestEditor() {
	}

	/**
	 * Create contents of the editor part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		
		Form frmCodeSmell = formToolkit.createForm(parent);
		formToolkit.paintBordersFor(frmCodeSmell);
		frmCodeSmell.setText("Refused Bequest");
		frmCodeSmell.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
		
		TabFolder tabFolder = new TabFolder(frmCodeSmell.getBody(), SWT.NONE);
		formToolkit.adapt(tabFolder);
		formToolkit.paintBordersFor(tabFolder);
		
		ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		sc.setExpandHorizontal(true);
	    sc.setExpandVertical(true);
		
		TabItem tbtmDescription = new TabItem(tabFolder, SWT.NONE);
		tbtmDescription.setText("Descri\u00E7\u00E3o");
		
		ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmDescription.setControl(scrolledComposite);
		formToolkit.paintBordersFor(scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		Composite composite_3 = new Composite(scrolledComposite, SWT.NONE);
		formToolkit.adapt(composite_3);
		formToolkit.paintBordersFor(composite_3);
		composite_3.setLayout(null);
		
		Label lblDescription = new Label(composite_3, SWT.NONE);
		lblDescription.setBounds(10, 10, 102, 25);
		lblDescription.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblDescription.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		formToolkit.adapt(lblDescription, true, true);
		lblDescription.setText("Descri\u00E7\u00E3o");
		
		Label label = new Label(composite_3, SWT.NONE);
		label.setImage(ResourceManager.getPluginImage("RefactorTips", "images/codeSmells/refusedBequest.png"));
		label.setBounds(10, 92, 450, 218);
		formToolkit.adapt(label, true, true);
		
		Link linkPushDownMethod = new Link(composite_3, SWT.NONE);
		linkPushDownMethod.setBounds(474, 235, 137, 21);
		linkPushDownMethod.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		formToolkit.adapt(linkPushDownMethod, true, true);
		linkPushDownMethod.setText("<a>Push Down Method</a>");
		
		Link linkPushDownField = new Link(composite_3, 0);
		linkPushDownField.setText("<a>Push Down Field</a>");
		linkPushDownField.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkPushDownField.setBounds(635, 235, 116, 21);
		formToolkit.adapt(linkPushDownField, true, true);
		
		Link linkReplaceInheritanceWithDelegation = new Link(composite_3, 0);
		linkReplaceInheritanceWithDelegation.setText("<a>Replace Inheritance with Delegation</a>");
		linkReplaceInheritanceWithDelegation.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkReplaceInheritanceWithDelegation.setBounds(23, 567, 248, 21);
		formToolkit.adapt(linkReplaceInheritanceWithDelegation, true, true);
		
		StyledText styledText = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText.setEnabled(false);
		styledText.setDoubleClickEnabled(false);
		styledText.setJustify(true);
		styledText.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText.setText("\t\tSubclasses herdam m\u00E9todos e dados de seus pais. Mas e se eles n\u00E3o quiserem ou precisarem o que s\u00E3o dados a eles? Eles recebem todos esses presentes maravilhosos e escolhem apenas alguns para brincar.");
		styledText.setBounds(474, 64, 411, 104);
		formToolkit.adapt(styledText);
		formToolkit.paintBordersFor(styledText);
		
		StyledText styledText_1 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_1.setText("\t\tTradicionalmente isso significa que a hierarquia est\u00E1 incorreta. Voc\u00EA precisa criar uma nova classe irm\u00E3 e usar \t\t\t\t\t\t\t\t\te \t\t\t\t\t\t\t\t\tpara empurrar todos os m\u00E9todos n\u00E3o usados para o irm\u00E3o. Dessa forma o pai cont\u00E9m apenas o que \u00E9 comum. Normalmente voc\u00EA ir\u00E1 ouvir a sugest\u00E3o que todas as superclasses devem ser abstratas.");
		styledText_1.setJustify(true);
		styledText_1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_1.setEnabled(false);
		styledText_1.setDoubleClickEnabled(false);
		styledText_1.setBounds(474, 192, 411, 148);
		formToolkit.adapt(styledText_1);
		formToolkit.paintBordersFor(styledText_1);
		
		StyledText styledText_2 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_2.setText("\t\tVoc\u00EA ir\u00E1 deduzir de nosso uso nocivo de tradicional que n\u00E3o vamos sugerir isso, pelo menos n\u00E3o todas \u00E0s vezes. N\u00F3s criamos subclasses para reusar uma parte do comportamento todas as vezes, e n\u00F3s percebemos que \u00E9 uma maneira perfeitamente boa de fazer neg\u00F3cios. Existe um mal cheiro, n\u00E3o podemos negar, mas normalmente n\u00E3o \u00E9 um mal cheiro forte. Ent\u00E3o n\u00F3s dizemos que se a \u201Cheran\u00E7a recusada\u201D est\u00E1 causando confus\u00E3o e problemas, siga a sugest\u00E3o tradicional. Entretanto, n\u00E3o sinta a necessidade de fazer isso sempre. Em cada nove vezes de dez esse mal cheiro \u00E9 muito fraco para valer a pena ser limpo.");
		styledText_2.setJustify(true);
		styledText_2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_2.setEnabled(false);
		styledText_2.setDoubleClickEnabled(false);
		styledText_2.setBounds(23, 363, 862, 135);
		formToolkit.adapt(styledText_2);
		formToolkit.paintBordersFor(styledText_2);
		
		StyledText styledText_3 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_3.setText("\t\tO mal cheiro de \u201Cheran\u00E7a recusada\u201D \u00E9 muito mais forte se a subclasse est\u00E1 reusando o comportamento mas n\u00E3o quer dar suporte a interface da superclasse. N\u00F3s n\u00E3o ligamos se implementa\u00E7\u00F5es s\u00E3o recusadas, mas recusar interface nos deixa chateados. Nesse caso, entretanto, n\u00E3o perca tempo com a hierarquia; voc\u00EA dever\u00E1 destrip\u00E1-lo aplicando \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t.");
		styledText_3.setJustify(true);
		styledText_3.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_3.setEnabled(false);
		styledText_3.setDoubleClickEnabled(false);
		styledText_3.setBounds(23, 504, 862, 135);
		formToolkit.adapt(styledText_3);
		formToolkit.paintBordersFor(styledText_3);
		scrolledComposite.setContent(composite_3);
		scrolledComposite.setMinSize(composite_3.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmUsage = new TabItem(tabFolder, SWT.NONE);
		tbtmUsage.setText("Exemplo");
		
		ScrolledComposite scrolledComposite_1 = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmUsage.setControl(scrolledComposite_1);
		formToolkit.paintBordersFor(scrolledComposite_1);
		scrolledComposite_1.setExpandHorizontal(true);
		scrolledComposite_1.setExpandVertical(true);
		
		Composite composite = new Composite(scrolledComposite_1, SWT.NONE);
		formToolkit.adapt(composite);
		formToolkit.paintBordersFor(composite);
		
		Label label_1 = new Label(composite, SWT.NONE);
		label_1.setImage(ResourceManager.getPluginImage("RefactorTips", "images/codeSmells/refusedBequest/refusedBequestSample1.1.png"));
		label_1.setBounds(10, 100, 395, 364);
		formToolkit.adapt(label_1, true, true);
		
		Label label_2 = new Label(composite, SWT.NONE);
		label_2.setImage(ResourceManager.getPluginImage("RefactorTips", "images/rightPointer.png"));
		label_2.setBounds(443, 260, 66, 36);
		formToolkit.adapt(label_2, true, true);
		
		Label label_3 = new Label(composite, SWT.NONE);
		label_3.setImage(ResourceManager.getPluginImage("RefactorTips", "images/codeSmells/refusedBequest/refusedBequestSample1.2.png"));
		label_3.setBounds(550, 126, 483, 338);
		formToolkit.adapt(label_3, true, true);
		scrolledComposite_1.setContent(composite);
		scrolledComposite_1.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmVideo = new TabItem(tabFolder, SWT.NONE);
		tbtmVideo.setText("Video");
		
		Browser browser = new Browser(tabFolder, SWT.NONE);
		browser.setUrl("www.youtube.com/embed/Y25apubA9jI");
		tbtmVideo.setControl(browser);
		formToolkit.paintBordersFor(browser);
	}
}
